package com.chaodev.base.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.chaodev.base.model.DataPageVO;
import com.chaodev.base.dao.DictDao;
import com.chaodev.base.model.Dict;
import com.chaodev.base.model.DictDetail;
import com.chaodev.base.model.ZtreeModel;
import com.chaodev.base.service.IDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DictServiceImpl implements IDictService {
    @Autowired
    private DictDao dictDao;

    @Override
    public PageInfo<Dict> dictQuery(DataPageVO dataPage) {
        PageHelper.startPage(dataPage.getPage(), dataPage.getRows());
        List<Dict> list = dictDao.dictQuery(dataPage);
        PageInfo<Dict> pageInfo = new PageInfo<>(list, dataPage.getRows());
        return pageInfo;
    }

    @Override
    public boolean dictAdd(Dict dict) {
        Integer result=dictDao.dictAdd(dict);
        return result>0;
    }

    @Override
    public boolean dictUpdate(Dict dict) {
        return dictDao.dictUpdate(dict)>0;
    }

    @Override
    public boolean dictDelete(Map<String,Object> map) {
        Integer result=dictDao.dictDelete(map);
        return result>0;
    }

    @Override
    public Dict getDictInfo(Map<String, Object> map) {
        return dictDao.getDictInfo(map);
    }

    @Override
    public Integer validateDict(Dict dict) {
        return dictDao.validateDict(dict);
    }

    @Override
    public List<ZtreeModel> dictDetailQuery(DictDetail dictDetail) {
//        PageHelper.startPage(dataPage.getPage(), dataPage.getRows());
//        List<DictDetail> list = dictDao.dictDetailQuery(dataPage);
//        PageInfo<DictDetail> pageInfo = new PageInfo<>(list, dataPage.getRows());
//        return pageInfo;
        List<ZtreeModel> list = dictDao.dictDetailQuery(dictDetail);
        return list;
    }

    @Override
    public boolean insertDictDetail(DictDetail dictDetail) {
        return dictDao.insertDictDetail(dictDetail)>0;
    }

    @Override
    public boolean updateDictDetail(DictDetail dictDetail) {
        return dictDao.updateDictDetail(dictDetail)>0;
    }

    @Override
    public boolean deleteDictDetail(Map<String, Object> map) {
        return dictDao.deleteDictDetail(map)>0;
    }

    @Override
    public DictDetail getDictDetailInfo(Map<String, Object> map) {
        return dictDao.getDictDetailInfo(map);
    }

    @Override
    public Integer validateDictDetail(DictDetail dictDetail) {
        return dictDao.validateDictDetail(dictDetail);
    }
}
